<template>
    <div>
    <h1>医生信息添加</h1>
    <table class="table">
        <thead>
           
            <tr>
                <td>医生姓名</td>
                <td>
                    <input type="text" v-model="data.name">
                </td>
            </tr>
            <tr>
                <td>头像</td>
                <td>
                    <input type="file" @change="UpLoad">
                    <img :src="'https://localhost:7140'+data.img" style="height: 60px;width: 60px;">
                </td>
            </tr>
            <tr>
                <td>所属科室</td>
                <td>
                    <select v-model="data.cid">
                        <option value="0">请选择</option>
                        <option v-for="a in swert"  :value="a.cid">{{ a.name }}</option>
                    </select>
                </td>
            </tr>
           
           
            <tr>
                <td>创建日期</td>
                <td>
                    <input type="date" v-model="data.endTime">
                </td>
            </tr>
            <tr>
                
                <td colspan="2">
                    <input type="button" value="添加" @click="Add">
                </td>
            </tr>
        </thead>
    </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import moment from "moment";
const data=ref({
    "id": 0,
  "name": "",
  "img": "",
  "cid": 0,
  "endTime": "2025-05-19T03:33:22.910Z"
})
onMounted(()=>{
    Xiala()
})
const swert=ref([{
    "cid": 1,
    "name": "内科",
}])
const Xiala=()=>{
    axios.get("https://localhost:7140/api/Room/Xiala").then(res=>{
        swert.value=res.data
    })
}
const Add=()=>{
    if(data.value.name==""){
        alert('医生姓名不能为空');
        return;
    }
   
    axios.post("https://localhost:7140/api/Order/AddOrder",data.value).then(res=>{
    if(res.data>0){
        alert('添加成功');
        location.href='/ShowView';
    }
    else{
        alert('添加失败');
    }
    })
}
const UpLoad=(e:any)=>{
    var f=e.target.files[0]
    var fd=new FormData()
    fd.append("file",f)
    
    axios.post("https://localhost:7140/api/UPload/upload",fd).then(res=>{
        data.value.img=res.data
    })
}
</script>

<style scoped>

</style>